<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
	<body>
		<h1 class="pagetitle">
			修改供应商物料
		</h1>
		
		<div class="column1-unit">
				新增物料
				<s:form method="post" id="formID" action="supplier!confirmParts.action"
					validate="true" theme="css_xhtml">
						<s:hidden name="supplier.id"></s:hidden>
						<table class="formtable">
							<tr>
								<td width="150">
									物料类别
								</td>
								<td>
									<select id="partsType"></select>
								</td>
							</tr>
								<tr>
								<td width="150">
									物料名称
								</td>
								<td>
									<select id="parts" name="parts.id"></select>
								</td>
							</tr>
						</table>
						
						<s:submit cssClass="button" theme="simple"></s:submit>
						<s:reset cssClass="button" theme="simple"></s:reset>

						<br><br>
						<table class="formtable">
							<s:iterator value="supplier.partsTypeList"  status="pl">
							<tr>
								<td width="150">
									<s:property value="name"/>
								</td>
								<td>
									<s:iterator value="partsList">
										<div><s:property value="name"/><div style="float:right"><a href="supplier!deleteParts.action?supplier.id=${supplier.id }&parts.id=${id}">删除物料</a></div></div>
									</s:iterator>
								</td>
							</tr>
							</s:iterator>
						</table>

						
				</s:form>
		</div>
<script type="text/javascript">
//方法1
$.getJSON("ajax!partsType.action", function(myJSON){  
    var myOptions = '<option value="-999">-----------</option>';  
    for (var i = 0; i < myJSON.length; i++) {  
        myOptions += '<option value="' + myJSON[i].id+ '">' + myJSON[i].name + '</option>';                       
    }  
    $("#partsType").html(myOptions);
});

$("#partsType").change(function(){
	var partsTypeValue = $("#partsType").val();
	if(partsTypeValue == null || partsTypeValue == -999){
		//alert(partsTypeValue);
		$("#parts").html('');  
		return;
	}
    $.getJSON("ajax!parts.action",{id: $(this).val()}, function(myJSON){ 
        var myOptions = '';  
        for (var i = 0; i < myJSON.length; i++) {  
            myOptions += '<option value="' + myJSON[i].id + '">' + myJSON[i].name + '</option>';                        }  
        $("#parts").html(myOptions);  
    });  
}); 
$("#partsType").change();  


/* 方法2
$("#partsType").FillOptions(   
     "ajax!partsType.action",   
     {   
     datatype:"json",   
     textfield:"name",   
     valuefiled:"id",   
     selectedindex:0,//填充并选中第1项   
     keepold:true//填充并且保留原有项   
     }   
);  

$("#partsType").AddOption("物料大类：","-1",true,0);//最上端插入一个文本为“请选择省份“，值为”-1“的列表项，并且是选中状态   
//$("#parts").AddOption("物料小类：","-1",true,0);   
$("#partsType").CascadingSelect(   
        $("#parts"),//需要联动的下拉列表框，必须   
        "ajax!parts.action",   
        {datatype:"json",textfield:"name",valuefiled:"id",parameter:"id"},//通过设置parameter:”p”这个参数会生成一个"handler1.ashx?p=xxx”这样的地址来做ajax请求   
        function(){//完成联动后执行   
             //log.info("测试");   
        }   
);  */
</script>	
	</body>
	
</html>